﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZedGraph;
using System.Drawing;

namespace GeostatisticalTool.Classes
{
    class CrossValidationCheck
    {
        private ZedGraphControl zed;
        private List<double[]> list;
        public CrossValidationCheck(ZedGraphControl zed, List<double[]> list)
        {
            this.zed=zed;
            this.list = list;
        }

        public void DrawPoints(String labelX, String labelY, String title,int indeXList, int indexYList)
        {
            zed.GraphPane.CurveList.Clear();
            ZedGraph.LineItem myPoint = zed.GraphPane.AddCurve("points", list[indeXList], list[indexYList], Color.Red);
            myPoint.Symbol.Type = ZedGraph.SymbolType.Circle;
            myPoint.Line.IsVisible=false;
            zed.GraphPane.XAxis.Title.Text = labelX;
            zed.GraphPane.YAxis.Title.Text = labelY;

            //refresh the graph
            zed.AxisChange();

            //set the graph title
            zed.GraphPane.Title.Text = title;
            zed.Refresh();
        
        }


        public void GuideLine(double z)
        {
            CurveItem theo = zed.GraphPane.CurveList["guide"];
            if (theo != null)
                zed.GraphPane.CurveList.Remove(theo);

            ZedGraph.LineItem myCurve = zed.GraphPane.AddCurve("guide", new double[2]{0,z},new double[2]{0,z}, Color.Gray);
            myCurve.Line.Width = 1f;
            myCurve.Symbol.Type = ZedGraph.SymbolType.None;
            zed.Refresh();
        }

        public void RegressionLine(double z,double slope, double intercept)
        {
            CurveItem theo = zed.GraphPane.CurveList["Regression"];
            if (theo != null)
                zed.GraphPane.CurveList.Remove(theo);

            ZedGraph.LineItem myCurve = zed.GraphPane.AddCurve("Regression", new double[2] { 0, z }, new double[2] { GetValueLine(slope, intercept, 0), GetValueLine(slope, intercept, z) }, Color.Blue);
            myCurve.Line.Width = 1f;
            myCurve.Symbol.Type = ZedGraph.SymbolType.None;
            zed.Refresh();
        }

        private double GetValueLine(double slope, double intercept,double trueValue)
        {
            return intercept + slope * trueValue;
        }
    }
}
